package com.gitee.sop.layui.adminserver.module.background.admin.rest;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gitee.sop.layui.adminserver.module.background.admin.dto.SysDataOperateHistoryDTO;
import com.gitee.sop.layui.adminserver.module.background.admin.entity.SysDataOperateHistory;
import com.gitee.sop.layui.adminserver.module.background.admin.service.SysDataOperateHistoryService;
import com.gitee.sop.layui.adminserver.module.base.constants.Result;
import com.gitee.sop.layui.adminserver.module.base.util.ObjectUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * com.gitee.sop.adminserver.modules.background.admin.entity.SysDataOperateHistory模型http接口处理
 *
 * @author: admin
 * @date: 2020-04-24
 * @version: 1.0.0
 */
@RestController
@RequestMapping(value = "/admin/sysDataOperateHistory", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class SysDataOperateHistoryRestController {

    @Lazy
    @Resource
    private SysDataOperateHistoryService baseService;

    @PostMapping(value = {"/add"})
    public Result add(SysDataOperateHistoryDTO query) {
        SysDataOperateHistory SysDataOperateHistory = new SysDataOperateHistory();
        ObjectUtil.switchAllFieldValue(SysDataOperateHistory, query);
        baseService.save(SysDataOperateHistory);
        return Result.success();
    }

    @PostMapping(value = {"/delete/id/{id}"})
    public Result deleteById(@PathVariable(value = "id") Integer id) {
        baseService.removeById(id);
        return Result.success();
    }

    @PostMapping(value = {"/update/id/{id}"})
    public Result updateById(@PathVariable(value = "id") Integer id, SysDataOperateHistoryDTO query) {
        SysDataOperateHistory SysDataOperateHistory = new SysDataOperateHistory();
        ObjectUtil.switchAllFieldValue(SysDataOperateHistory, query);
        baseService.updateById(SysDataOperateHistory);
        return Result.success();
    }

    @RequestMapping(value = {"/search/all"})
    public Result searchAll() {
        List<SysDataOperateHistory> list = baseService.list();
        return Result.success(list);
    }

    @RequestMapping(value = {"/search/page"})
    public Result searchPage(@RequestParam(required = false) Integer current, @RequestParam(required = false) Integer size) {
        IPage<SysDataOperateHistory> page = baseService.page(new Page<>(current, size));
        return Result.success(page);
    }

    @RequestMapping(value = {"/search/id/{id}"})
    public Result searchOneById(@PathVariable(value = "id") Integer id) {
        SysDataOperateHistory SysDataOperateHistory = baseService.getById(id);
        return Result.success(SysDataOperateHistory);
    }
}
